<template>
  <div class="flex flex-col">
    <div class="flex flex-row aic">
      <!--搜索条件-->
      <Screen :data="props.conditionData.searchData" />
      <!-- 按钮事件 -->
      <Button :data="props.conditionData.optData" @btnTap="btnTap" />
      <!-- 高级搜索条件 -->
      <div class="flex flex-row aic mb-12px" v-if="props.conditionData.advanceData.length">
        <div class="flex flex-row aic cursor-pointer" @click="advTap">
          <span class="text-13px text-gray-500">高级搜索</span>
          <img v-if="is_adv" class="ml-10px" pub:w="11px" pub:h="6px" src="@/assets/images/up-adv.png" />
          <img v-else class="ml-10px" pub:w="11px" pub:h="6px" src="@/assets/images/down-adv.png" />
        </div>
      </div>
    </div>
    <div class="flex flex-row" v-if="is_adv && props.conditionData.advanceData.length">
      <!--高级条件-->
      <Screen :data="props.conditionData.advanceData" />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import Screen from './Screen/index.vue';
import Button from './Button/index.vue';
import { getValue } from '@/hooks/common';
const props = defineProps({
  conditionData: {
    type: Object,
    default: {},
  },
});
const is_adv = ref<boolean>(false);
const advTap = function () {
  is_adv.value = !is_adv.value;
};
const emit = defineEmits<{
  (e: 'screen', params: object): void; //按钮事件
}>();
const screen = function (params: Object) {
  emit('screen', params);
};
const btnTap = function (e: any) {
  switch (e.key) {
    case 'screen':
      let params = {};

			console.log(is_adv,'is_adv')
      if (is_adv.value) {
        params = getValue([...props.conditionData.searchData, ...props.conditionData.advanceData]);
      } else {
        params = getValue(props.conditionData.searchData);
      }
      screen(params);
      break;
    case 'reset':
      console.log('reset');
      props.conditionData.searchData.forEach((item: any) => {
        if (item.type == 'multiple') {
          item.value = [];
        } else if (item.type == 'select') {
          item.value = undefined;
        } else if (item.type == 'cascadeSel') {
          item.value = undefined;
          item.child.value = [];
        } else {
          item.value = '';
        }
      });
      props.conditionData.advanceData.forEach((item: any) => {
        if (item.type == 'multiple') {
          item.value = [];
        } else if (item.type == 'select') {
          item.value = undefined;
        } else if (item.type == 'cascadeSel') {
          item.value = undefined;
          item.child.value = [];
        } else {
          item.value = '';
        }
      });
      break;
    default:
      console.log('无事');
  }
};
console.log(props.conditionData);
</script>
